package com.ruoyi.demo.web.controller;

import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.helper.LoginHelper;
import com.ruoyi.demo.database.WebJdbcFactory;
import com.smartframework.web.core.bean.ResultVO;
import com.zhr.jdbc.WebJdbcClient;


import javafx.scene.control.Tab;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author LIUJUN
 */
@RestController
@RequestMapping("/cloud/demo")
public class DemoController {
    @Autowired
    private WebJdbcFactory webJdbcFactory;

    /**
     * 测试数据列表
     */
    @GetMapping("/list")
    public TableDataInfo<SysUser> list() {
        List<SysUser> userList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            SysUser user = new SysUser();
            user.setUserName("demo-" + i);
            userList.add(user);
        }
        LoginUser loginUser = LoginHelper.getLoginUser();
        return TableDataInfo.build(userList);
    }

    @GetMapping("/masterlab")
    public TableDataInfo<List<Map<String,Object>>> accounts() {
        WebJdbcClient webJdbcClient = webJdbcFactory.buildNewClient();
        if (ObjectUtil.isNull(webJdbcClient)) {
            //TODO throw Exception for other process
            return null;
        }
        ResultVO resultVO = webJdbcClient.queryForList("select * from sys_web_user");
        return TableDataInfo.build((List)resultVO.getData());
    }
}
